<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="五金入库单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
              <a-input v-model="model.code" placeholder="五金入库单号" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="审批流程" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="flowType">
              <j-dict-select-tag
                type="list"
                v-model="model.flowType"
                dictCode="hardware_store_flow_type"
                placeholder="请选择审批流程"
                :disabled="formDisabled"
              />
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item
              label="供货单位"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="supplierCompany"
            >
              <a-input v-model="model.supplierCompany" placeholder="" :disabled="true"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="进厂日期"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="enterPlantDate"
            >
              <j-date
                placeholder="请选择日期"
                v-model="model.enterPlantDate"
                style="width: 100%"
                :disabled="formDisabled"
              />
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="宝洁供应商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pgSupplierName">
              <j-popup
                v-model="model.pgSupplierName"
                field="pgSupplierName"
                org-fields="supplier_name,supplier_code,id"
                dest-fields="pgSupplierName,pgSupplierCode,pgSupplierId"
                code="purchase_supplier_info"
                :multi="false"
                @input="popupCallback"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="宝洁供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pgSupplierCode">
              <a-input v-model="model.pgSupplierCode" placeholder="选择供应商后自动带出" :disabled="true"></a-input>
            </a-form-model-item>
          </a-col>
          <a-input v-model="model.pgSupplierId" type="hidden"></a-input>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item
              label="保洁采购订单号"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="pgPurchaseOrderNo"
            >
              <a-input v-model="model.pgPurchaseOrderNo" placeholder="请输入保洁采购订单号"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>



        <a-row>
          <a-col :span="12">
            <a-form-model-item
              label="当前车牌号："
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="plateNumber"
            >
              <plate-number-input
                v-model="model.plateNumber"
                @change="handleInput"
              />
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item
              label="司机名称"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="driverName"
            >
              <a-input v-model="model.driverName"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>


        <a-row>
          <a-col :span="12">
            <a-form-model-item
              label="联系方式"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="driverPhone"
              :rules="rules.driverPhone"
            >
              <a-input v-model="model.driverPhone"></a-input>
            </a-form-model-item>
          </a-col>


          <a-col :span="12" >
            <a-form-model-item label="进厂目的" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purpose">
              <j-dict-select-tag
                type="list"
                v-model="model.purpose"
                dictCode="driver_purpose"
              />
            </a-form-model-item>
          </a-col>
        </a-row>






        <a-row style="margin-left: -16.6%;margin-top: 5px">
          <a-col :span="24">
            <a-form-model-item
              label="备注"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="remark"
            >
              <!--<a-input v-model="model.remark" placeholder=""></a-input>-->
              <a-textarea
                :disabled="formDisabled"
                v-model="model.remark"
                :rows="5"
                allow-clear
                showCount
                placeholder=""
              ></a-textarea>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row style="margin-top: 20px">
        </a-row>

        <a-row>
          <a-col :span="24">
            <j-vxe-table
              keep-source
              :ref="refKeys[1]"
              :loading="fileTable.loading"
              :columns="fileTable.columns"
              :dataSource="fileTable.dataSource"
              :maxHeight="300"
              :disabled="formDisabled"
              :rowNumber="true"
              :rowSelection="true"
              :toolbar="true"
            >
              <template v-slot:action="props">
                <a @click="handlePreviewFile(props)">预览</a>
              </template>
            </j-vxe-table>
          </a-col>
        </a-row>

        <a-input v-model="model.sourceFrom" type="hidden" />

        <a-input v-model="model.procurementOrderId" type="hidden" />

        <a-input v-model="model.warehouseCode" type="hidden" />

      </a-form-model>
    </j-form-container>
    <!-- 子表单区域 -->
    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <a-tab-pane tab="原料入库通知单明细" :key="refKeys[0]" :forceRender="true">
        <a-row>
          <a-col :span="24">
            <j-vxe-table
              keep-source
              :ref="refKeys[0]"
              :loading="bussMaterialProcurementDetailTable.loading"
              :columns="bussMaterialProcurementDetailTable.columns"
              :dataSource="bussMaterialProcurementDetailTable.dataSource"
              :maxHeight="300"
              :disabled="formDisabled"
              :rowNumber="false"
              :rowSelection="false"
              class="j-table-force-nowrap1"
              :clickSelectRow="true"
              rowSelectionType="radio"
              @edit-closed="editClosedEvent"
            >
              <!--<template v-slot:action="props">
                <a-popconfirm
                  v-show="!formDisabled"
                  title="确定删除吗？"
                  @confirm="handleDelDetail(props)"
                >
                  <a>删除</a>
                </a-popconfirm>
              </template>-->
            </j-vxe-table>
          </a-col>
        </a-row>
      </a-tab-pane>
    </a-tabs>
  </a-spin>
</template>

<script>
  import { getAction, httpAction, postAction } from '@/api/manage'
  import { getRefPromise, VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'
  import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin'
  import { JVXETypes } from '@/components/jeecg/JVxeTable'
  import store from '@/store'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import moment from 'dayjs'
  import ErpGoodsSupplier from '@/components/base/ErpGoodsSupplier'
  import GoodsSupplier from '@/components/base/GoodsSupplier'
  import { initDictOptions } from '@/components/dict/JDictSelectUtil'
  import TslSupplier from '@comp/tsl/TslSupplier.vue'
  import { definitionStartByDataId, isFirstInitiator } from '@views/flowable/api/definition'
  import TslSelectUserSingle from '@/components/tsl/TslSelectUserSingle.vue'
  import { FilePreview } from '@/utils/tslCommon'
  import Decimal from "decimal.js";
  import PlateNumberInput from '@views/srm/materialstore/modules/PlateNumberInput.vue'

  export default {
    name: 'BussMaterialProcurementForm',
    mixins: [JVxeTableModelMixin],
    components: {
      PlateNumberInput,
      JSelectDepart,
      ErpGoodsSupplier,
      GoodsSupplier,
      TslSupplier,
      TslSelectUserSingle,
    },
    data() {
      return {


        rules: {
          driverPhone: [
            { required: true, message: '请输入联系电话', trigger: 'blur' },
            {
              pattern: /^1[3-9]\d{9}$/,
              message: '请输入11位手机号码',
              trigger: 'blur'
            }
          ]
        },

        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        dict: {
          unit: [{ label: '个', value: '1' }],
        },
        priceTypeOption: [
          {
            value: '到库价格',
            label: '到库价格',
          },
          {
            value: '出厂价格',
            label: '出厂价格',
          },
          {
            value: '到港价格',
            label: '到港价格',
          },
        ],
        model: {
          sourceFrom: '2',
          flowType: '1',
          code: '',
          supplierCompany: '',
          remark: '',
          procurementOrderDetailId: '',
          procurementOrderId: '',
          procurementOrderCode: '',
          procurementPlanCode: '',
          applicationCode: '',
          warehouseCode: '',
          plateNumber: '', // 确保 model 中有 plateNumber 字段
          province: '', // 确保 model 中有 province 字段
          plateBody: '', // 确保 model 中有 plateBody 字段

          /*enterPlantDate: '',
          pgSupplierName: '',
          pgSupplierCode: '',
          pgSupplierId: '',
          pgPurchaseOrderNo: '',*/
          bussMaterialStoreNoticeDetailList: [],
          bussStoreNoticeFilesList: [],
        },
        supplier: {},
        supplyShow: true,
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
          /*code: [{ required: true, message: '请输入单据编号!' }],
          purchaseBy: [{ required: true, message: '请填写发件人' }],
          supplierBy: [{ required: true, message: '请填写收件人' }],
          transport: [{ required: true, message: '请选择运输方式' }],
          arrivalPlace: [{ required: true, message: '请填写收货地址' }],
          payment: [{ required: true, message: '请选择付款方式' }],
          paymentTime: [{ required: true, message: '请填写付款时间' }],
          arrivalDate: [{ required: true, message: '请填写到货日期' }],*/
          purpose: [{ required: true, message: '请选择来车目的' }],
          driverName: [{ required: true, message: '请司机名称!' }],
          plateNumber: [{ required: true, message: '请填写车牌号' }],
        },
        refKeys: ['bussMaterialProcurementDetail','fileTable'],
        tableKeys: ['bussMaterialProcurementDetail'],
        activeKey: 'bussMaterialProcurementDetail',
        // 原料入库通知单明细
        bussMaterialProcurementDetailTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '序号',
              key: 'seq',
              type: JVXETypes.normal,
              width: '50px',
            },
            {
              title: '五金采购订单号',
              key: 'procurementOrderCode',
              type: JVXETypes.normal,
              width: '150px',
            },
            {
              title: '五金计划单号',
              key: 'procurementPlanCode',
              type: JVXETypes.normal,
              width: '150px',
            },
            {
              title: '五金请购单号',
              key: 'applicationCode',
              type: JVXETypes.normal,
              width: '150px',
            },
            {
              title: '物料编码',
              key: 'materialCode',
              type: JVXETypes.normal,
              width: '120px',
            },
            {
              title: '物料名称',
              key: 'materialName',
              type: JVXETypes.normal,
              width: '120px',
            },
            {
              title: '规格型号',
              key: 'spec',
              type: JVXETypes.normal,
              width: '120px',
            },
            {
              title: '单位',
              key: 'unit',
              type: JVXETypes.normal,
              width: '50px',
            },
            {
              title: '采购订单数量',
              key: 'procurementOrderNum',
              type: JVXETypes.normal,
              width: '120px',
            },
            {
              title: '已转入库单数量',
              key: 'transferredStoreNum',
              type: JVXETypes.normal,
              width: '120px',
            },
            {
              title: '未转入库单数量',
              key: 'notTransferredStoreNum',
              type: JVXETypes.normal,
              width: '120px',
            },
            {
              title: '已到数量',
              key: 'arrivedNum',
              type: JVXETypes.normal,
              width: '120px',
            },
            {
              title: '不合格数量',
              key: 'unqualifiedNum',
              type: JVXETypes.normal,
              width: '120px',
            },
            {
              title: '实收数量',
              key: 'actualAcceptNum',
              type: JVXETypes.normal,
              width: '120px',
            },
            {
              title: '本次转入库单数量',
              key: 'curTransferredStoreNum',
              type: JVXETypes.inputNumber,
              width: '120px',
            },
            /*{
              title: '操作',
              key: 'action',
              type: JVXETypes.slot,
              fixed: 'right',
              minWidth: '100px',
              align: 'center',
              slotName: 'action',
            },*/
          ],
        },
        fileTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '附件',
              key: 'filePath',
              type: JVXETypes.file,
              token: true,
              disabled:this.formDisabled,
              responseName: 'message',
              width: '200px',
              placeholder: '请选择文件',
              defaultValue: '',
            },
            {
              title: '附件说明',
              key: 'fileDesc',
              type: JVXETypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '操作',
              key: 'action',
              type: JVXETypes.slot,
              fixed: 'right',
              minWidth: '100px',
              align: 'center',
              slotName: 'action',
            },
          ],
        },
        url: {
          add: '/bussmaterialstorenotice/bussMaterialStoreNotice/add',
          edit: '/bussmaterialstorenotice/bussMaterialStoreNotice/edit',
          queryById: '/bussmaterialstorenotice/bussMaterialStoreNotice/queryById',
          bussMaterialProcurementDetail: {
            list: '/bussmaterialstorenotice/bussMaterialStoreNotice/queryBussMaterialStoreNoticeDetailByMainId',
          },
        },
        unitDictOptions: {},
        zlunitDictOptions: {},
      }
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false,
      },
      customFormData: {
        type: Object,
        default: () => {
          return {}
        },
        required: false,
      },
    },
    computed: {
      formDisabled() {
        return this.disabled
      },
    },
    created() {
      this.model.sourceFrom = '2'

      this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss')
      let user = store.getters.userInfo
      if (!this.model.createBy) {
        this.model.createBy = user.username
        this.model.createOrgcode = user.departIds
      }

      this.initDictConfig()

      //如果是审批流进来的时候要将审批流的数据显示出来
      if (this.customFormData.id != null) {
        this.model = this.customFormData
        //刷新子表数据
        this.editAfter()
      }

      if (!this.model.id) { // 仅新增时添加默认行
        this.fileTable.dataSource = [{}];
      }
    },
    mounted() {},
    methods: {
      getPfCode() {
        postAction('/sys/fillRule/executeRuleByCode/hardware_store_code', {}).then((res) => {
          this.model.code = res.result
        })
      },
      initDictConfig() {
        //初始化字典 - 主单位
        initDictOptions('ji_unit').then((res) => {
          let unitDictOptions = this.unitDictOptions
          if (res.success) {
            res.result.forEach(function (item, index) {
              unitDictOptions[item.value] = item.label
            })
          }
          this.unitDictOptions = unitDictOptions
        })
        //初始化字典 - 辅单位
        initDictOptions('zl_unit').then((res) => {
          let zlunitDictOptions = this.zlunitDictOptions
          console.log(res)
          if (res.success) {
            res.result.forEach(function (item, index) {
              zlunitDictOptions[item.value] = item.label
            })
          }
          this.zlunitDictOptions = zlunitDictOptions
        })
      },
      addTemporary() {
        //临时新增
        if (this.model.bussMaterialStoreNoticeDetailList && this.model.bussMaterialStoreNoticeDetailList.length > 0 && this.model.bussMaterialStoreNoticeDetailList[0].planCode) {
          this.$XModal.message({ message: '临时不能与计划混加', status: 'warning' })
          return
        }
        this.$nextTick(() => {
          this.$refs.selectGoodsList.add()
        })
      },
      handlerok(record) {
        if (!record) {
          return
        }
        if (
          this.bussMaterialProcurementDetailTable.dataSource &&
          this.bussMaterialProcurementDetailTable.dataSource.length > 0
        ) {
          let item = this.bussMaterialProcurementDetailTable.dataSource.find(
            (item) => item.procurementPlanId === record.detailId
          )
          if (item) {
            this.$message.warning('该计划单已选择！')
            return
          }
        }
        let isPush = true
        let _this = this
        let detail = {}
        detail.materialName = record.materialName
        detail.materialCode = record.materialCode
        detail.materialId = record.materialId
        detail.planCode = record.code
        detail.procurementNum = record.unPurchaseNum
        detail.procurementArrayPrice = 0
        detail.spec = record.spec
        detail.unit = record.meUnit
        detail.procurementPlanId = record.detailId
        detail.supplierId = record.supplierId
        detail.arrivalDate = record.arrivalDate
        detail.planNum = record.num
        detail.planGenerateNum = record.purchaseNum
        detail.planLeftNum = record.unPurchaseNum
        detail.procurementPlanNo = record.code
        detail.seq = this.bussMaterialProcurementDetailTable.dataSource.length + 1
        detail.planSeq = record.seq
        if (
          this.bussMaterialProcurementDetailTable.dataSource &&
          this.bussMaterialProcurementDetailTable.dataSource > 0
        ) {
          let isPush = this.bussMaterialProcurementDetailTable.dataSource.find(
            (item) => item.procurementPlanId === record.detailId
          )
          if (!isPush) {
            _this.$message.warning('只能选择同一个原料采购计划单')
            return
          }
        }
        if (isPush) {
          this.model.bussMaterialStoreNoticeDetailList.push(detail)
          this.bussMaterialProcurementDetailTable.dataSource.push(detail)
          if (this.bussMaterialProcurementDetailTable.dataSource.length > 0) {
            this.loadVendor(this.model.bussMaterialStoreNoticeDetailList[0].supplierId)
          }
        }
      },
      addPlan() {
        //追加选择采购计划
        this.$nextTick(() => {
          this.$refs.plan.add()
        })
      },
      goodsOk(record) {
        let detail = {}
        detail.materialName = record.name
        detail.materialCode = record.code
        detail.materialId = record.id
        detail.spec = record.noneSpec
        detail.unit = record.meUnit_dictText
        detail.supplierId = record.supplierId
        this.bussMaterialProcurementDetailTable.dataSource.push(detail)
        this.loadVendor()
      },
      loadVendor() {
        if (this.model.bussMaterialStoreNoticeDetailList && this.model.bussMaterialStoreNoticeDetailList.length > 0 && this.model.bussMaterialStoreNoticeDetailList[0].supplierId) {
          // 加载供应商信息
          getAction('/base/erpSupplier/queryById', { id: this.model.bussMaterialStoreNoticeDetailList[0].supplierId }).then((res) => {
            this.supplier = res.result
            this.model.supplierId = this.supplier.id
          })
        }
      },
      showDetails(id) {
        getAction('/bussmaterialstorenotice/bussMaterialStoreNotice/getDetailInfos', { procurementOrderId: id }).then((res) => {
          let data = res.result
          data.forEach((row, index) => {
            this.bussMaterialProcurementDetailTable.dataSource.push({
              procurementOrderCode: row.procurementOrderCode,
              procurementPlanCode: row.procurementPlanCode,
              applicationCode: row.applicationCode,
              procurementOrderDetailId: row.procurementOrderDetailId,
              procurementOrderId: row.procurementOrderId,
              materialId: row.materialId,
              materialCode: row.materialCode,
              materialName: row.materialName,
              spec: row.spec,
              unit: row.unit,
              procurementOrderNum: row.procurementOrderNum,
              seq: index + 1,
            })
          })
        })
      },
      selectSupplier() {
        //选择供应商
        this.$nextTick(() => {
          this.$refs.supplier.add()
        })
      },
      initSupplier(result) {
        if (this.supplier && this.supplier.id != result.id) {
          this.supplier = {}
          this.model.bussMaterialStoreNoticeDetailList = []
        }
        this.supplier = result
        this.model.supplierId = this.supplier.id
      },
      addBefore() {
        this.bussMaterialProcurementDetailTable.dataSource = []
        this.fileTable.dataSource = []
      },
      add() {
        this.getPfCode()
        //这里单位字段获取不到怎么解决
        this.bussMaterialProcurementDetailTable.dataSource = []
        let purchaseOrderDetailList = store.getters.purchaseOrderDetailList
        if (purchaseOrderDetailList.length > 0) {
          // 供货单位设定
          this.model.supplierCompany = purchaseOrderDetailList[0].supplierName
          // 供货单位设定
          this.model.remark = "发件人：" + purchaseOrderDetailList[0].supplierBy + "， 发件人电话：" + purchaseOrderDetailList[0].supplierPhone + "， 运输方式：" + purchaseOrderDetailList[0].transport_dictText
          // 采购单ID
          this.model.procurementOrderId = purchaseOrderDetailList[0].id
          // 采购单code
          this.model.procurementOrderCode = purchaseOrderDetailList[0].code
          // 物料所属仓库
          this.model.warehouseCode = purchaseOrderDetailList[0].warehouseCode

          this.bussMaterialProcurementDetailTable.dataSource = purchaseOrderDetailList.map((item, index) => ({
            procurementOrderCode: item.procurementCode,
            procurementPlanCode: item.procurementPlanCode,
            applicationCode: item.applicationCode,
            procurementOrderDetailId: item.detailId,
            procurementOrderId: item.id,
            materialId: item.materialId,
            materialCode: item.materialCode,
            materialName: item.materialName,
            spec: item.spec,
            unit: item.unit,
            procurementOrderNum: item.curTransferredNum,
            transferredStoreNum: item.transferredStoreNum,
            notTransferredStoreNum: item.notTransferredStoreNum,
            arrivedNum: item.arrivedNum,
            unqualifiedNum: item.unqualifiedNum,
            actualAcceptNum: item.actualAcceptNum,
            curTransferredStoreNum : ((new Decimal(item.curTransferredNum || 0).minus(new Decimal(item.transferredStoreNum || 0))).plus(new Decimal(item.unqualifiedNum || 0))).toString(),
            seq: index + 1,
          }));
          /*if (tempList[0].id) {
            this.showDetails(tempList[0].id)
          }*/
        }
      },
      editClosedEvent({ row, column, cellValue }) {
        // 当修改"本次订单数量"或"价格"时触发计算
        if (['curTransferredNum', 'price'].includes(column.property)) {
          // 确保值为数字类型
          const qty = parseFloat(row.curTransferredNum) || 0
          const price = parseFloat(row.price) || 0

          // 计算总价（保留两位小数）
          row.totalPrice = (qty * price).toFixed(2)
        }
      },
      getAllTable() {
        let values = this.tableKeys.map((key) => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter(record) {
        //如果没有明细先要复制一个空数组
        if (!record || record.bussMaterialStoreNoticeDetailList == null) {
          this.model.bussMaterialStoreNoticeDetailList = []
        }

        if (this.model.id) {
          let params = { id: this.model.id }
          this.requestSubTableData(
            this.url.bussMaterialProcurementDetail.list,
            params,
            this.bussMaterialProcurementDetailTable,
            this.fileTable
          )

          //刷新明细的时候 还要将这个数据传输到要提交的表单中
          if (this.bussMaterialProcurementDetailTable) {
            this.model.bussMaterialStoreNoticeDetailList = this.bussMaterialProcurementDetailTable.dataSource
          }

          if (this.fileTable) {
            this.model.bussStoreNoticeFilesList = this.fileTable.dataSource
          }
        }

        this.$nextTick(() => {})
      },
      requestSubTableData(url, params, table, fileTable) {
        getAction(url, params).then(res => {
          if (res.success) {
            table.dataSource = res.result.bussMaterialStoreNoticeDetailList.map(item => ({
              ...item,
              //totalPrice: (item.curTransferredNum * item.price).toFixed(2)
            }))
            fileTable.dataSource = res.result.bussStoreNoticeFilesList
          }
        })
      },
      successBack(res) {
        let { result } = res
        this.model = result
        if (this.model.bussMaterialStoreNoticeDetailList && this.model.bussMaterialStoreNoticeDetailList.length > 0) {
          this.loadVendor()
        }
      },
      //校验所有一对一子表表单
      validateSubForm(allValues) {
        return new Promise((resolve, reject) => {
          Promise.all([])
            .then(() => {
              resolve(allValues)
            })
            .catch((e) => {
              if (e.error === VALIDATE_NO_PASSED) {
                // 如果有未通过表单验证的子表，就自动跳转到它所在的tab
                this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
              } else {
                validateError(e)
              }
            })
        })
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)
        return {
          ...main, // 展开
          bussMaterialProcurementdetaillist: allValues.tablesValue[0].values,
        }
      },
      validateError(msg) {
        this.$message.error(msg)
      },
      submitForm() {
        const that = this
        // 触发表单验证
        this.$refs.bussMaterialProcurementDetail.validateTable().then((errMap) => {
          if (errMap) {
            this.$message.error('请检查表单明细内容')
            return
          } else {
            this.$refs.form.validate((valid) => {
              if (valid) {
                that.confirmLoading = true
                let httpurl = ''
                let method = ''
                if (!this.model.id) {
                  httpurl += this.url.add
                  method = 'post'
                } else {
                  httpurl += this.url.edit
                  method = 'put'
                }

                if (this.bussMaterialProcurementDetailTable && this.bussMaterialProcurementDetailTable.dataSource) {
                  this.model.bussMaterialStoreNoticeDetailList = this.bussMaterialProcurementDetailTable.dataSource
                  this.model.bussMaterialStoreNoticeDetailList.forEach((element) => {
                    element.id = null
                  })
                }

                if (this.fileTable && this.fileTable.dataSource) {
                  this.model.bussStoreNoticeFilesList = this.$refs.fileTable.getTableData()
                  this.model.bussStoreNoticeFilesList.forEach((element) => {
                    element.id = null
                  })
                }

                if (!this.model.bussMaterialStoreNoticeDetailList || this.model.bussMaterialStoreNoticeDetailList.length <= 0) {
                  this.$message.warning('没有选择任何物料不能保存')
                  that.confirmLoading = false
                  return
                }
                console.log(this.model)
                httpAction(httpurl, this.model, method)
                  .then((res) => {
                    if (res.success) {
                      //241119修改提交时还要判断是否直接进入审批流
                      /*if (!this.model.id) {
                        this.model.dataId = res.message
                        that.applySubmit(this.model)
                      }*/
                      that.$message.success('保存成功')
                      that.$emit('ok')
                      that.close()
                    } else {
                      that.$message.warning(res.message)
                    }
                  })
                  .finally(() => {
                    that.confirmLoading = false
                  })
              }
            })
          }
        })
      },
      applySubmit(record) {
        if (record.dataId && record.dataId.length < 1) {
          this.$message.error('审批时必须传入参数dataId')
          return
        }

        //对于自定义业务，判断是否是驳回或退回的第一个发起人节点

        isFirstInitiator(record.dataId, record).then((res) => {
          if (res.success && res.result) {
            // 只有第一次能自动申请
            return
          } else {
            let params = Object.assign(
              {
                dataId: record.dataId,
              },
              record
            )
            //this.queryParams.createTime = parseTime(new Date())
            definitionStartByDataId(record.dataId, 'materialProcurementService', params)
              .then((res) => {
                if (res.success) {
                  this.$message.success(res.message)
                } else {
                  this.$message.error(res.message)
                }
              })
              .finally()
          }
        })
      },
      onSelectSupplier({ result: record }) {
        this.model.supplierName = record.name
        this.model.supplierId = record.id
        this.model.supplierNo = record.code
        this.model.supplierAddress = record.address
        this.model.supplierBy = record.contact
        this.model.supplierPhone = record.telephone
        this.model.supplierTax = record.fax
        this.model.supplierMail = record.email
        this.model.supplierBank = record.bankName
        this.model.supplierAccount = record.accountNo
        this.model.supplierMail = record.zipCode
        this.$forceUpdate()
      },
      /*handleDelDetail(props) {
        props.target.removeRows(props.row)
        this.bussMaterialProcurementDetailTable.dataSource.splice(
          this.bussMaterialProcurementDetailTable.dataSource.findIndex((d) => d.id === props.row.id),
          1
        )
      },*/
      handleOk() {
        //空方法 防止多次提交
      },
      popupCallback(value,row){
        this.model = Object.assign(this.model, row);
      },
      handlePreviewFile(row) {
        console.log(row);
        let filePath = row.row.filePath
        FilePreview(filePath);
      },

      handleInput(val) {
        console.log('车牌号变更11:', val)
        this.model.plateNumber = val.plateNumber; // 确保值正确更新
        this.model.province = val.province;
        this.model.plateBody = val.plateBody;
      },
    },
  }
</script>

<style scoped>
  .ant-form-item {
    margin-bottom: 4px;
    margin-left: 4px;
  }
  .ant-input-affix-wrapper {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    color: rgba(0, 0, 0, 0.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    list-style: none;
    font-feature-settings: 'tnum';
    position: relative;
    display: inline-block;
    width: 107%;
    text-align: start;
  }
</style>
